/**
 * Created by zouyao on 2017/3/6.
 */
var teacherEvaluateSelfCtrl = m.controller("teacherEvaluateSelfcontroller",function ($rootScope,$scope) {

    /**
     * 初始化
     */
    $rootScope.tes_init = function () {
        $scope.prevPage = "上一页";
        $scope.nextPage = "下一页";
        $scope.currentPage = 1;
        $scope.totalPage = 1;
        $scope.constRef = [["查看详情"]];
        $scope.blurName = "";
        $scope.orderType = "";

        $scope.editSuccessStatus = false;

        $scope.getSelfRecord();
    };
    /**
     * 获取自我评估记录
     */
    $scope.getSelfRecord = function () {
        //获取我的评价记录
        $.ajax({
            type:"POST",
            url:"/comment/getCommentRecordByUserId",
            data:{"studentId":$rootScope.idOfLoger,"teacherId":$rootScope.idOfLoger},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success:function(data){
                console.log(data);
                $scope.$apply(function(){
                    if(data.message == "无记录" || data.value == null){
                        $scope.selfCommentTemp = ""
                    }else {
                        $scope.selfCommentTemp = data.value.comment;
                    }
                });
            }
        });
        //获取我的评分记录
        $.ajax({
            type:"POST",
            url:"/score/getScoreRecordByUserId",
            data:{"studentId":$rootScope.idOfLoger,"teacherId":$rootScope.idOfLoger},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success:function(data){
                console.log(data);
                $scope.$apply(function(){
                    if(data.message == "无记录" || data.value == null){
                        $scope.selfScoreTemp = 1;
                    }else {
                        $scope.selfScoreTemp = data.value.score;
                    }
                });
            }
        });
    }
    /**
     * 提交自我评估
     */
    $scope.editSelfRecord = function () {
        $.ajax({
            type:"POST",
            url:"/comment/setCommentScoreForTeacher",
            data:{"comment":$scope.selfCommentTemp,"score":$scope.selfScoreTemp,"studentId":$rootScope.idOfLoger,"teacherId":$rootScope.idOfLoger},
            contentType:"application/x-www-form-urlencoded",
            dataType:"json",
            success:function(data){
                console.log(data);
                $scope.$apply(function(){
                    $scope.getSelfRecord();
                    $scope.editSuccessStatus = true;
                   /* if(data.message == "无记录" || data.value == null){

                    }else {
                        $scope.selfScoreTemp = data.value.score;
                    }*/
                });
            }
        });
    };
    $scope.changeStatus = function () {
        $scope.editSuccessStatus = false;
    };

});